//
//  ViewController.m
//  WCDBDemo
//
//  Created by jiangdong on 2018/3/30.
//  Copyright © 2018年 jiangdong. All rights reserved.
//

#import "ViewController.h"
#import "SZYWCDBManager.h"
#import "SZYMessage.h"
#import "SZYDetailScore.h"

@interface ViewController ()

@end

@implementation ViewController


//插入数据
- (IBAction)insertData:(id)sender {
    //插入多个数据
    [self insertDatas];
    //插入单个数据
//    [self insertSingleData];
}


//查询
- (IBAction)selectData:(id)sender {
    [[SZYWCDBManager shareInstance] selectData];
}

//更新表
- (IBAction)update:(id)sender {
    [[SZYWCDBManager shareInstance] updateData];

}

//删除表
- (IBAction)deletaTable:(id)sender {
    [[SZYWCDBManager shareInstance] deleteData];
}

//插入单个数据
- (void)insertSingleData {
    SZYMessage *message1 = [[SZYMessage alloc] init];
    message1.name = @"xiaoming4239";
    message1.localID = 1;
    message1.totalScore = arc4random() % 100;
    SZYDetailScore *detailScore1 = [[SZYDetailScore alloc] init];
    detailScore1.math = arc4random() % 100;
    detailScore1.english = arc4random() % 100;
    message1.detailScore = detailScore1;
    
    [[SZYWCDBManager shareInstance] insertData:message1];
}

//插入多个数据
- (void)insertDatas {
    //构建数据
    NSMutableArray *objects = [[NSMutableArray alloc] init];
    SZYMessage *message1 = [[SZYMessage alloc] init];
    message1.name = @"xiaoming";
    message1.localID = 1;
    message1.totalScore = arc4random() % 100;
    SZYDetailScore *detailScore1 = [[SZYDetailScore alloc] init];
    detailScore1.math = arc4random() % 100;
    detailScore1.english = arc4random() % 100;
    message1.detailScore = detailScore1;
    [objects addObject:message1];
    
    SZYMessage *message2 = [[SZYMessage alloc] init];
    message2.name = @"lili";
    message2.localID = 2;
    message2.totalScore = arc4random() % 100;
    message2.isPass = YES;
    
    SZYDetailScore *detailScore2 = [[SZYDetailScore alloc] init];
    detailScore2.math = arc4random() % 100;
    detailScore2.english = arc4random() % 100;
    message2.detailScore = detailScore2;
    [objects addObject:message2];
    
    SZYMessage *message3 = [[SZYMessage alloc] init];
    message3.name = @"lilei6";
    message3.localID = 3;
    message3.totalScore = arc4random() % 100;
    message3.isPass = YES;
    
    SZYDetailScore *detailScore3 = [[SZYDetailScore alloc] init];
    detailScore3.math = arc4random() % 100;
    detailScore3.english = arc4random() % 100;
    message3.detailScore = detailScore3;
    [objects addObject:message3];
    
    SZYMessage *message4 = [[SZYMessage alloc] init];
    message4.name = @"jiang";
    message4.localID = 4;
    message4.totalScore = arc4random() % 100;
    SZYDetailScore *detailScore4 = [[SZYDetailScore alloc] init];
    detailScore4.math = arc4random() % 100;
    detailScore4.english = arc4random() % 100;

    message4.detailScore = detailScore4;
    [objects addObject:message4];
    
    [[SZYWCDBManager shareInstance] insertDatas:objects];
}

@end
